package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.entity.CarStyle;

/**
 * @author zhangxueliang
 * 根据车辆款式载入车辆排量和发动机类型
 */
public class CarInfoLoadByCarStyleAjaxAction extends TmsAjaxAction{

	private Logger logger = Logger.getLogger(CarInfoLoadByCarStyleAjaxAction.class);
	private static final String CARSTYLEID = "carStyleId";
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc)throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		controller.begin();
		CarStyle carStyle = CarStyle.getInstance();
		String carStyleId = request.getParameter(CARSTYLEID);
		double displacement =  carStyle.getExhaustByCarStyleId(carStyleId);
		int gearbox = carStyle.getGearboxByCarStyleId(carStyleId);
		//拼接字符串 （排量，变速箱类型）
		StringBuffer str = new StringBuffer();
		str.append(displacement);
		str.append(",");
		str.append(gearbox);
		controller.commit();
		String responseText =str.toString();
		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}

}
